package guestbook;

import java.io.IOException;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.*;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import guestbook.RSS_data;
import guestbook.PMF;

public class DeleteRSSdataServlet extends HttpServlet {
	private static final Logger log = Logger.getLogger(DeleteRSSdataServlet.class.getName());

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
				throws IOException {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		String name = "Nobody";
		if(user != null) name = user.getNickname();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		log.info("Persistence Manager opened.");
		try {
			Query query = pm.newQuery("select from " + RSS_data.class.getName());
			List<RSS_data> objs = (List<RSS_data>) query.execute();
			pm.deletePersistentAll(objs);
			
		} finally {
			pm.close();
			log.info("Persistence Manager closed.");
		}
		resp.sendRedirect("/guestbook.jsp");
	}
}

/**
	PersistenceManager pm = PMF.get().getPersistenceManager();
	Query query = pm.newQuery("select from " + Your.class);
	List<Your> objs = (List<Your>) query.execute();
	pm.deletePersistentAll(objs);
*/
